﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi
{
    public partial class mfDjackVehicleInfo : msBsc.Cls.mbPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        public override void DoAction()
        {
            if (this.strAction == "GetVehicleList")
            {
                ShowPersonInfo();
            }
        }

        private void ShowPersonInfo()
        {
            string urlParm = this.GetParamHtValue("DjackId");
            if (string.IsNullOrEmpty(urlParm))
            {
                string currentUrl = this.GetParamHtValue("currentUrl");

                string refferUrl = HttpContext.Current.Request.UrlReferrer.ToString();

                if (currentUrl == refferUrl)
                {
                    refferUrl = "http://www.dijieke.com/mp_home.htm";
                }
                this.ExecJScript("window.location.href='" + refferUrl + "'");
            }

            using (msBsc.AppLogic.DataAlc.CBizDjackSpecieInfo objCBizDjackSpecieInfo = new AppLogic.DataAlc.CBizDjackSpecieInfo())
            {
                Epm.AppLogic.Framework.CDbParmCollection parmCollection = new Epm.AppLogic.Framework.CDbParmCollection();
                parmCollection.Add(new Epm.AppLogic.Framework.CDbParm("djackId", ParameterDirection.Input, Epm.AppLogic.Framework.EDbType.String, 36, urlParm.Replace("'", "").Replace(",", "','")));

                DataSet ds = objCBizDjackSpecieInfo.DataObj.QueryBySQL(@"SELECT
T4.DJACK_SPECIEINFO_ID
,T4.DJACK_INTRODUCE
,T4.CUSTOMER_NICK
,T4.CUSTOMER_DEFAULT_PIC
,T4.COUNTRY_NAME
,T4.CITY_NAME
,F.COUNTRY_CITY_NME D_NAME
FROM (SELECT
T3.*
,E.COUNTRY_CITY_NME CITY_NAME
FROM (SELECT
T2.*
,D.COUNTRY_CITY_NME COUNTRY_NAME
FROM (SELECT
T1.*
,C.CUSTOMER_NICK
,C.CUSTOMER_DEFAULT_PIC
FROM (SELECT
T.*
,B.CUSTOMER_DISTINATION_ID
,B.CUSTOMER_CITY_ID
,B.CUSTOMER_COUNTRY_ID
FROM (SELECT
A.DJACK_SPECIEINFO_ID
,A.DJACK_INTRODUCE
FROM DJK_DJACK_SPECIEINFO A
WHERE A.DJACK_SPECIEINFO_ID=@djackId) T
LEFT JOIN DJK_CUSTOMER_BASEINFO B ON T.DJACK_SPECIEINFO_ID=B.CUSTOMER_BASEINFO_ID) T1
LEFT JOIN DJK_CUSTOMER_REGISTER C ON T1.DJACK_SPECIEINFO_ID=C.CUSTOMER_REGISTER_ID) T2
LEFT JOIN DJK_COUNTRY_CITY D ON T2.CUSTOMER_COUNTRY_ID=D.COUNTRY_CITY_ID) T3
LEFT JOIN DJK_COUNTRY_CITY E ON T3.CUSTOMER_CITY_ID=E.COUNTRY_CITY_ID) T4
LEFT JOIN DJK_COUNTRY_CITY F ON T4.CUSTOMER_DISTINATION_ID=F.COUNTRY_CITY_ID", parmCollection);

                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    this.ExecJScript("window.location.href='http://www.dijieke.com/mp_home.htm'");
                }
                else
                {
                    string distination = ds.Tables[0].Rows[0]["COUNTRY_NAME"].ToString() + "·" + ds.Tables[0].Rows[0]["CITY_NAME"].ToString() + "·" + ds.Tables[0].Rows[0]["D_NAME"].ToString();

                    this.ExecJScript("$('#djkHeadPic').attr('src','/UpLoad/Djack/" + ds.Tables[0].Rows[0]["CUSTOMER_DEFAULT_PIC"].ToString() + "'); $('#mbDjackNick').text('" + ds.Tables[0].Rows[0]["CUSTOMER_NICK"].ToString() + "'); $('#mbDestination').text('" + distination + "'); $('#mbDjackIntro').text('" + ds.Tables[0].Rows[0]["DJACK_INTRODUCE"].ToString() + "')");
                    ShowVehicleList(ds.Tables[0].Rows[0]["DJACK_SPECIEINFO_ID"].ToString());
                }
            }
        }

        private void ShowVehicleList(string djackId)
        {
            Epm.AppLogic.Framework.CDbParmCollection parmCollection = new Epm.AppLogic.Framework.CDbParmCollection();
            parmCollection.Add(new Epm.AppLogic.Framework.CDbParm("djackId", ParameterDirection.Input, Epm.AppLogic.Framework.EDbType.String, 36, djackId));

            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo objCBizVehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                DataSet ds = objCBizVehicleInfo.DataObj.QueryBySQL(@"
SELECT
A.VEHICLE_DEFAULT_PIC
,A.VEHICLE_NAME
,A.VEHICLE_BRAND
,A.VEHICLE_SEATS
,A.VEHICLE_SERVICE_TYPE
,A.VEHICLE_PRICE_DAY
FROM DJK_VEHICLE_INFO A
WHERE DJACK_ID=@djackId", parmCollection);

                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
                    return;
                }

                string retJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 500, "");
                this.ExecJScript(@"
                            var _html = $('#vehicleList_xmp').html();

                            laytpl(_html).render(" + retJson + @", function (render) {
                                $('#vehicleList_ul').html(render);
                            });");
            }
        }
    }
}